/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.atomos.log
{
	import com.bourre.log.Logger;
	import com.bourre.events.EventChannel;
	
	/**
	 * <code>AtomosDebug</code> utils dispatch log within Atomos.
	 * 
	 * <p>You can be notified of Atomos logs by registering to the
	 * <code>Logger</code> instance on the <code>AtomosDebug.CHANNEL</code>
	 * property.</p> 
	 */
	public class AtomosDebug
	{
		/**
		 * You can disable or enable the Atomos debug by switching
		 * the <code>isOn</code> property with <code>true|false</code>.
		 * 
		 * @example	Disabling the whole debug from Atomos 
		 * <listing>AtomosDebug.isOn = false;</listing>
		 */
		public static var isOn : Boolean = true;
		
		// private reference to the channel
		private static var _CHANNEL : EventChannel;
		
		/**
		 * Returns the Atomos' <code>EventChannel</code> instance.
		 * 
		 * @return Atomos' <code>EventChannel</code> instance.
		 */
		public static function get CHANNEL() : EventChannel
		{
			if ( !AtomosDebug._CHANNEL ) AtomosDebug._CHANNEL = new AtomosDebugChannel();
			return AtomosDebug._CHANNEL;
		}
		
		/**
		 * Dispath a log on the <code>Logger</code> instance with
		 * <code>DEBUG</code> level.
		 * 
		 * @param 	o	Any data to log.
		 */
		public static function DEBUG( o : * ) : void
		{
			if (AtomosDebug.isOn) Logger.DEBUG( o, AtomosDebug.CHANNEL );
		}
		
		/**
		 * Dispath a log on the <code>Logger</code> instance with
		 * <code>INFO</code> level.
		 * 
		 * @param 	o	Any data to log.
		 */
		public static function INFO( o : * ) : void
		{
			if (AtomosDebug.isOn) Logger.INFO( o, AtomosDebug.CHANNEL );
		}
		
		/**
		 * Dispath a log on the <code>Logger</code> instance with
		 * <code>WARN</code> level.
		 * 
		 * @param 	o	Any data to log.
		 */
		public static function WARN( o : * ) : void
		{
			if (AtomosDebug.isOn) Logger.WARN( o, AtomosDebug.CHANNEL );
		}
		
		/**
		 * Dispath a log on the <code>Logger</code> instance with
		 * <code>ERROR</code> level.
		 * 
		 * @param 	o	Any data to log.
		 */
		public static function ERROR( o : * ) : void
		{
			if (AtomosDebug.isOn) Logger.ERROR( o, AtomosDebug.CHANNEL );
		}
		
		/**
		 * Dispath a log on the <code>Logger</code> instance with
		 * <code>FATAL</code> level.
		 * 
		 * @param 	o	Any data to log.
		 */
		public static function FATAL( o : * ) : void
		{
			if (AtomosDebug.isOn) Logger.FATAL( o, AtomosDebug.CHANNEL );
		}
	}
}

import com.bourre.events.EventChannel;

internal class AtomosDebugChannel extends EventChannel {}